/*
 * @Author: intellectual seeker 3336339701@qq.com
 * @Date: 2024-12-19 10:36:23
 * @LastEditors: intellectual seeker 3336339701@qq.com
 * @LastEditTime: 2024-12-19 11:43:26
 * @FilePath: /linux-learning/code/lesson23/mystdio.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
//C语言库缓冲区与文件接口的简单模拟实现
//文件操作相关系统调用接口需包含的头文件
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define SIZE 4096

#define NONE_FLUSH (1<<1)
#define LINE_FLUSH (1<<2)
#define FULL_FLUSH (1<<3)

typedef struct _myFILE
{
    //char* inbuffer[SIZE]; //输入缓冲区
    char outbuffer[SIZE];  //输出缓冲区
    int cap;                //容量
    int pos;                //写入位置
    int fileno;             //文件描述符
    int flush_mode;        //刷新模式
}_myFILE;

//打开文件
_myFILE* myfopen(const char* pathname, const char* mode);

//写入内容
int myfwrite(_myFILE* fp, const char* s, int size);

//关闭文件
void myfclose(_myFILE* fp);

//刷新
void my_fflush(_myFILE* fp);

void DebugPrint(_myFILE* fp);

const char* toString(int flush_mode);